package com.vijos;

//超长数字串
public class P8_3_1005 {

    public static int test(String in) {
        char[] chars = in.toCharArray();
        int length = 0;
        for (int i = 1; i <= Integer.MAX_VALUE; ) {
            String str = "" + i;
            int index = str.indexOf(chars[0]);
            int temp = 1;
            boolean append = false;
            int lengthBack = 0;
            if (index != -1) {
                while (chars.length > (str.length() - index)) {
                    str += (i + temp++);
                    append = true;
                }
                if (append) {
                    temp -= 1;
                    lengthBack = ("" + (i + temp)).length();
                }
                if (str.indexOf(in) != -1) {
                    return length + index + 1;
                }
            }
            i = i + temp;
            length += str.length() - lengthBack;
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(test("1314"));
    }
}
